#include "bsp_font.h"
#include "main.h"

#define IPS114_W 270
#define IPS114_H 240

#define IPS114_PENCOLOR BLUE /* ĺĺ­çŹçé˘č˛ */
#define IPS114_BGCOLOR BLACK /* čćŻé˘č˛ */

typedef enum {
  VERTICAL_SCREEN = 0,     /* çŤĺąć¨Ąĺź */
  VERTICAL_SCREEN_180 = 1, /* çŤĺąć¨Ąĺź,ćč˝Ź180 */
  HORIZON_SCREEN = 2,      /* ć¨?ĺąć¨Ąĺź? */
  HORIZON_SCREEN_180 = 3,  /* ć¨?ĺąć¨Ąĺź?,ćč˝Ź180 */
} LCD_ScreenDirection_t;

#define IPS114_DISPLAY_DIR HORIZON_SCREEN_180

#if (0 == IPS114_DISPLAY_DIR || 1 == IPS114_DISPLAY_DIR)
#define IPS114_X_MAX IPS114_W  //ćś˛ćśXćšĺ?˝ĺşŚ
#define IPS114_Y_MAX IPS114_H  //ćś˛ćśYćšĺ?˝ĺşŚ
#elif (2 == IPS114_DISPLAY_DIR || 3 == IPS114_DISPLAY_DIR)
#define IPS114_X_MAX IPS114_H  //ćś˛ćśXćšĺ?˝ĺşŚ
#define IPS114_Y_MAX IPS114_W  //ćś˛ćśYćšĺ?˝ĺşŚ
#else
#error "IPS114_DISPLAY_DIR ĺŽäšéč??"
#endif

/** ĺźčĺŽäš */
#define IPS114_SCL(x) \
  HAL_GPIO_WritePin(SPI2_SLK_GPIO_Port, SPI2_SLK_Pin, (GPIO_PinState)x)
#define IPS114_SDA(x) \
  HAL_GPIO_WritePin(SPI2_MOSI_GPIO_Port, SPI2_MOSI_Pin, (GPIO_PinState)x)
#define IPS114_REST(x) \
  HAL_GPIO_WritePin(SCREEN_RES_GPIO_Port, SCREEN_RES_Pin, (GPIO_PinState)x)
#define IPS114_DC(x) \
  HAL_GPIO_WritePin(SCREEN_DC_GPIO_Port, SCREEN_DC_Pin, (GPIO_PinState)x)
#define IPS114_CS(x) \
  HAL_GPIO_WritePin(SCREEN_CS_GPIO_Port, SCREEN_CS_Pin, (GPIO_PinState)x)

void Bsp_IpsWrCmd(uint8_t dat);
void Bsp_IpsWrData(uint8_t dat);
void Bsp_IpsWrData16(uint16_t dat);

void LCD_SetRegion(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_Clear(uint16_t color);

void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t ch);
void LCD_ShowString(uint16_t x, uint16_t y, uint8_t string[]);
void LCD_Show_int8_t(uint16_t x, uint16_t y, int8_t dat);
void LCD_Show_uint8_t(uint16_t x, uint16_t y, uint8_t dat);
void LCD_Show_int16_t(uint16_t x, uint16_t y, int16_t dat);
void LCD_Show_uint16_t(uint16_t x, uint16_t y, uint16_t dat);

void LCD_DisplayImg(uint8_t *p, uint16_t width, uint16_t height);
void LCD_DisplayImg_Zoom(uint8_t *p, uint16_t width, uint16_t height,
                         uint16_t dis_width, uint16_t dis_height);
void LCD_DisplayImg_7725(uint8_t *p, uint16_t width, uint16_t height);

void LCD_Display_Chinese(uint16_t x, uint16_t y, uint8_t size, const uint8_t *p,
                         uint8_t number, uint16_t color);
